<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  <meta name="description" content="">
  <meta name="author" content="ThemeBucket">
  <link rel="shortcut icon" href="#" type="image/png">

  <title>考勤管理</title>

  <!--data table-->
  <link rel="stylesheet" href="js/data-tables/DT_bootstrap.css" />

  <link href="css/style.css" rel="stylesheet">
  <link href="css/style-responsive.css" rel="stylesheet">

  <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!--[if lt IE 9]>
  <script src="js/html5shiv.js"></script>
  <script src="js/respond.min.js"></script>
  <![endif]-->

  <style type="text/css">
    #all_light { /*整个弹窗的页面*/
    opacity: 0.8; /*透明度*/
    width: 100%; /*宽度*/
    height: 2300px; /*高度，不能百分百*/
    background: #000; /*背景色*/
    position: absolute;
    top: 0;
    left: 0; /*定位*/
    display: none; /*隐藏*/
    z-index: 2; /*覆盖*/
    }
    #contes { /* 弹框的页面*/
    width: 500px; /*宽度*/
    height: 150px; /*高度*/
    background: #fff; /*背景色*/
    display: none; /*隐藏*/
    z-index: 2; /*覆盖*/
    position: absolute;
    top: 100px;
    left: 400px; /* 定位*/
    }
    input{
    margin-bottom: 10px;
    }
    </style>
</head>

<body class="sticky-header">
<div id="app">
<section>
    <!-- left side start-->
    <script src="left.js"></script>
    <!-- left side end-->
    
    <!-- main content start-->
    <div class="main-content" >

        <!-- header section start-->
        <div class="header-section">

        <!--toggle button start-->
        <a class="toggle-btn"><i class="fa fa-bars"></i></a>
        <!--toggle button end-->


        </div>
        <!-- header section end-->

        <!-- page heading start-->
        <div class="page-heading">
            <h3>
                考勤管理
            </h3>
            <ul class="breadcrumb">
                <li>
                    <a href="#">首页</a>
                </li>
                <li>
                    <a href="#">管理</a>
                </li>
                <li class="active"> 考勤管理 </li>
            </ul>
        </div>
        <!-- page heading end-->

        <!--body wrapper start-->
        <div class="wrapper">
             <div class="row">
                <div class="col-sm-12">
                <section class="panel">

                <div class="panel-body">
                <div class="adv-table editable-table ">
                <div class="clearfix">

                    <div class="btn-group pull-right">
                        <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">Tools <i class="fa fa-angle-down"></i>
                        </button>
                        <ul class="dropdown-menu pull-right">
                            <li><a href="#">Print</a></li>
                            <li><a href="#">Save as PDF</a></li>
                            <li><a href="#">Export to Excel</a></li>
                        </ul>
                    </div>
                </div>
                <div class="space15"></div>

<!--  弹框的div -->
<div id="contes" style="">
    <div >
    <hr>
    <form style=" margin-left: 100px;" id="dataform">
        <input type="hidden" id="id" name="id">
       加工资  :  <input type="text" value="" id="us1" name="us1" ><br>
       扣工资  :  <input type="text" value="" id="us2" name="us2" ><br>
  
    <button type="submit" onclick="submitform()">提交</button>
    <button type="button" onclick="cancel()">取消</button>
    </form>
    </div>
   </div>
   <div id="all_light">
   </div>

                <!-- 表格 -->
                <table class="table table-striped table-hover table-bordered"
                       id="editable-sample">
                <thead>
                <tr>
                    <th prop="id">考勤号</th>
                    <th prop="name">考勤人</th>
                    <th prop="workNums">工作量(处理订单量)</th>
                    <th prop="updateSalary">加/减工资</th>
                    <th prop="check_time">签到时间</th>

                    <th prop="salary">当前基本工资</th>
                    <th>操作</th>
                    <th>删除</th>
                </tr>
                </thead>

                <tbody id="newList">
                
                </tbody>
                </table>
                </div>
                
                </div>
                <div col-lg-6>
                    
                    <div class="dataTables_paginate paging_bootstrap pagination">
                        
                <ul id="pagination">
                   
                </ul>
            </div>
                </div>
                </section>
                </div>
                </div>
        </div>
        <!--body wrapper end-->

        <!--footer section start-->
       
        <!--footer section end-->


    </div>
    <!-- main content end-->
</section>
</div>
<!-- Placed js at the end of the document so the pages load faster -->
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery-ui-1.9.2.custom.min.js"></script>
<script src="js/jquery-migrate-1.2.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/modernizr.min.js"></script>
<script src="js/jquery.nicescroll.js"></script>

<!--data table-->
<script type="text/javascript" src="js/data-tables/jquery.dataTables.js"></script>
<script type="text/javascript" src="js/data-tables/DT_bootstrap.js"></script>

<!--common scripts for all pages-->
<script src="js/scripts.js"></script>

<!--script for editable table-->
<script src="js/editable-table.js"></script>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<!-- END JAVASCRIPTS -->
<script src="orders.js"></script>
<script>
    var pagination={ //分页信息
            currentPage:1,
            pageSize:5
        }

// 弹窗start
function cancel(){
    document.getElementById('contes').style.display = 'none';
}
function jump() {
    
 document.getElementById('all_light');
 document.getElementById('contes').style.display = 'block';
 }
 //弹窗end

//提交修改
function submitform(){
        var serialize = $("#dataform").serializeArray();
        var id=serialize[0].value;
        var addS=serialize[1].value;
        var subS=serialize[2].value;
    var updateSalary=parseFloat(addS)+parseFloat(subS*-1);

    $.ajax({ //更新和添加用同一个接口即可
        url:"/attend/Update",
        type:"POST",
        data: '{"id":"'+id+'",' +
            '"updateSalary":"'+updateSalary+'"}',
        contentType:"application/json;charset=UTF8",
        dataType:"json",
        success:function (res){
            if (res.success){
                alert(res.msg);
            }
            else{
                alert("操作失败!")
            }
        },
        error:function (){
            alert("莫名错误")
        }
    })
}

 //添加人员
 function addUser(){
    $("#dataform")[0].reset()
     jump();
 }
    jQuery(document).ready(function() {//初始化
        load();
    });
 
    //加/扣工资弹框
    function edit(i){
        $("#id").val(i);
        $("#us1").val(0);
        $("#us2").val(0);
        jump();
    }


    //展示列表
    function showList(list,sum,index){
        $('#newList').empty();

        for(var i=0;i<list.length;i++) {
            var tr="<tr>\n" +
                "<td>"+list[i].attend.id+"</td>\n" +
                "<td>"+list[i].sysUser.name+"</td>\n" +
                "<td>"+list[i].attend.workNums+"</td>\n" +
                "<td>"+list[i].attend.updateSalary+"</td>\n" +
                "<td>"+list[i].attend.checkTime+"</td>\n" +
                "<td>"+list[i].sysUser.salary+"</td>\n" +
                "<td><button  onclick=\"edit("+list[i].attend.id+")\">加/扣工资</button></td>\n" +
                "<td><button  onclick=\"delU("+list[i].attend.id+")\">删除考勤记录</button></td>\n" +
                "</tr>"
            $("#newList").append(tr);
        }

        $('#pagination').empty();
        for(var i=1;i<=sum;i++){
            if(i==index)var li="<li><button style='color: red' onclick=\"gopage("+i+")\">"+i+"</button></li>";
            else var li="<li><button onclick=\"gopage("+i+")\">"+i+"</button></li>";
            $("#pagination").append(li);
        }
    }

    //去xx页面
    function gopage(i){
        pagination.currentPage=i;//修改当前页码
        $.ajax({
            url:"/attend/getList",
            type:"POST",
            data:'{"currentPage":"'+pagination.currentPage+'","pageSize":"'+pagination.pageSize+'"}',
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    var l=res.data.list//重新赋值
                    var sum=res.data.totalPage;//更新总页数
                    showList(l,sum,i)
                }
                else{
                    alert("查询失败!")
                }
            },
            error:function (){

            }
        })


    }
    function load(){
        gopage(1);

    }


</script>

</body>
</html>
